home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.01 Jan 91 / Object Design / line feed removal / CmyFileManager.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-26  |  3.8 KB  |  156 lines  |  [TEXT/KAHL]

  1. /*
  2.  CmyFileManager.c
  3.  
  4.  this is the methods file for my file manager object.
  5.  
  6. */
  7. #include "oops.h"
  8. #include "MessageDefines.h"
  9. #include "Global.h"
  10. #include "CmyFileManager.h"
  11. #include "CApplication.h"
  12.  
  13. /**** Global Variables ****/
  14.  
  15. extern CApplication    *gApplication;        /* Application object                */
  16.  
  17. extern    OSType    gSignature;
  18.  
  19. /* ..................................................................... */
  20. void CmyFileManager::ImyFileManager(void)
  21. /*
  22.     Name: Wade Maxfield
  23.     Date: November 25, 1989
  24.     Notes:
  25.     initalize this object
  26.     Modification History:
  27. */
  28. {
  29.  
  30.     /* call the superclass function */
  31.     CDataFile::IDataFile();
  32. }
  33.  
  34. /* ..................................................................... */
  35. short CmyFileManager::GetExistingFile(SFReply *macSFReply)
  36. /*
  37.     Name: Wade Maxfield
  38.     Date: November 25, 1989
  39.     Notes:
  40.     put up the SFGetFile dialog box, return result in macSFReply
  41.     return a good message(ACK) or a bad message (NAK)
  42.     Modification History:
  43. */
  44. {
  45.  
  46.     gApplication->ChooseFile(macSFReply);
  47.     
  48.     if ( !macSFReply->good )
  49.         return(NAK);
  50.     else
  51.         return(ACK);
  52. }
  53. /* ..................................................................... */
  54. short  CmyFileManager::GetNewFile(SFReply *macSFReply,OSType fType)
  55. /*
  56.     Name: Wade Maxfield
  57.     Date: November 25, 1989
  58.     Notes:
  59.     put up the SFPutFile dialog box, return result in macSFReply
  60.     create the chosen file, or recreate it.
  61.     return a good message(ACK) or a bad message (NAK)
  62.     Modification History:
  63. */
  64. {
  65. Point        corner;                    /* Top left corner of dialog box    */
  66. SignedByte    saveHState;
  67. short returnMessage;
  68.                                         /* Center dialog box on the screen    */
  69.     FindDlogPosition('DLOG', gApplication->sfGetDLOGid, &corner);
  70.     
  71.     saveHState = HGetState(this);
  72.     HLock(this);
  73.  
  74.     SFPutFile(corner,"\pSave file as:","\p",NULL,macSFReply);
  75.     
  76.     HSetState(this, saveHState);
  77.     
  78.     /* now create the file for a future open. 
  79.       these methods are inherited. */
  80.     if ( macSFReply->good)
  81.         {
  82.         SFSpecify(macSFReply);
  83.         returnMessage = CreateNew(gSignature, fType );
  84.     
  85.         /* if is a duplicate, and user said ok to delete old,
  86.         then go ahead and re do it */
  87.         if ( returnMessage == dupFNErr && macSFReply->good)
  88.             {
  89.             ThrowOut(); /* get rid of old file */
  90.             returnMessage = CreateNew(gSignature, fType );
  91.             }
  92.         }
  93.  
  94.     if ( !macSFReply->good || returnMessage < 0)
  95.         return(NAK);
  96.     else
  97.         return(ACK);
  98.  
  99. }
  100. /* ..................................................................... */
  101. short  CmyFileManager::OpenFile(CmyDataFile **newDataFileObject,
  102.                                 SFReply *macSFReply)
  103. /*
  104.     Name: Wade Maxfield
  105.     Date: November 25, 1989
  106.     Notes:
  107.     Create a myDataFile object, and open the file, hand it back to
  108.     the calling method.
  109.     return a good message(ACK) or a bad message (NAK)
  110.     Modification History:
  111. */
  112. {
  113. short returnMessage;
  114.  
  115.     /* create the new file object */
  116.     *newDataFileObject = NULL; /* to allow test for object create */
  117.     *newDataFileObject = new(CmyDataFile);
  118.     
  119.     if (!(long)(*newDataFileObject)) /* object wasn't created */
  120.         return(NAK);
  121.         
  122.     (*newDataFileObject)->ImyDataFile();
  123.     
  124.     /* tell the inherited routine what file we have */
  125.     (*newDataFileObject)->SFSpecify(macSFReply); 
  126.     
  127.     returnMessage = (*newDataFileObject)->Open(fsRdWrPerm); /* call the inherited open */
  128.     
  129.     if ( returnMessage < 0 )
  130.         return(NAK); /* indicate an error (NAK) */
  131.         
  132.     
  133.     return(ACK); /* return a good message */
  134. }
  135.  
  136. /* ..................................................................... */
  137. short  CmyFileManager::CloseFile(CmyDataFile **dataFileObject)
  138. /*
  139.     Name: Wade Maxfield
  140.     Date: November 25, 1989
  141.     Notes:
  142.     Close the file and dispose of the data file object.
  143.     return a good message(ACK) 
  144.     Modification History:
  145. */
  146. {
  147.     /* first, close the file, then delete the file object */
  148.     (*dataFileObject)->Close();
  149.     
  150.     (*dataFileObject)->Dispose(); /* close and dispose of the object */
  151.     
  152.     *dataFileObject = NULL; /* indicate is gone */
  153.     
  154.     return(ACK); /* all quiet on western front */
  155. }
  156.